<template>
	<view class="btn-box">
		<button v-if="showBtnCancel" @tap.stop="onCancel(orderId)" class="cu-btn obtn1">取消订单</button>
		<button v-if="showBtnPay" @tap.stop="onPay(orderId)" class="cu-btn obtn2">付款</button>
		<button v-if="showBtnCheckExpress" @tap.stop="onCheckExpress(orderId)" class="cu-btn obtn1">查看物流</button>
		<button v-if="showBtnConfirm" @tap.stop="onConfirm(orderId)" class="cu-btn obtn2">确认收货</button>
	</view>
</template>
<script>
// - 已取消         TRADE_CLOSED （订单取消 未支付前可以申请取消 和 未发货前可以申请取消）
// - 待付款 nopay   WAIT_BUYER_PAY(等待买家付款)                                          默认支付时间为24小时 未支付则自动取消
// - 待发货 nosend  WAIT_SELLER_SEND_GOODS(等待卖家发货,即:买家已付款) 未发货前可以申请取消  默认48小时未发货自动退款并取消订单
// - 待收货 noget   WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货,即:卖家已发货)                默认自动收货时间15天，变已签收
// - 已签收         TRADE_FINISHED(交易成功) 
export default {
	props: {
		orderStatus: {
			type: String,
			required: true
		},
		orderId: {
			type: Number,
			required: true
		}
	},
	computed: {
		showBtnCancel: function () {
			return this.orderStatus === 'WAIT_BUYER_PAY'
		},
		showBtnPay: function () {
			return this.orderStatus === 'WAIT_BUYER_PAY'
		},
		showBtnCheckExpress: function () {
			return this.orderStatus === 'WAIT_BUYER_CONFIRM_GOODS'
		},
		showBtnConfirm: function () {
			return this.orderStatus === 'WAIT_BUYER_CONFIRM_GOODS'
		},
		
	},
	methods: {
		// 取消订单
		onCancel(orderId) {
			let that = this;
			that.$api('order.cancel', {
				orderId: orderId
			}).then(res => {
				if (res.code === 1) {
					that.$Router.back();
				}
			});
		},
		// 立即支付
		onPay(orderId) {
			uni.navigateTo({
				url: `/pages/order/payment/method?orderId=${orderId}`
			});
		},
		// 确认收货
		onConfirm(orderId) {
			let that = this;
			that.$api('order.confirm', {
				orderId: orderId
			}).then(res => {
				if (res.code === 1) {
					setTimeout(()=>{
						uni.redirectTo({
							url: this.$route.fullPath
						});
					},1000)
				}
			});
		},
		// 查看物流,
		onCheckExpress(orderId) {
			this.$Router.push({
				path: '/pages/order/express',
				query: { orderId }
			});
		}
	}
};
</script>
<style lang="scss">
.btn-box {
		justify-content: flex-end;
		.obtn1 {
			width: 160rpx;
			height: 60rpx;
			background: rgba(238, 238, 238, 1);
			border-radius: 30rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: rgba(51, 51, 51, 1);
			margin-right: 20rpx;
			padding: 0;
		}
		.obtn2 {
			width: 160rpx;
			height: 60rpx;
			background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
			box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
			border-radius: 30rpx;
			margin-right: 20rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: rgba(168, 112, 13, 0.9);
			padding: 0;
		}
	}
</style>
